import { ProgramContext } from '../gen/ArkcubeScriptParser';
import { ArkcubeScriptVisitor } from '../gen/ArkcubeScriptVisitor';
import { ParseTree } from 'antlr4ts/tree/ParseTree';
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor'
import { RuleNode } from 'antlr4ts/tree/RuleNode';
import { TerminalNode } from 'antlr4ts/tree/TerminalNode';
import { ErrorNode } from 'antlr4ts/tree/ErrorNode';
import { TokenStreamRewriter } from 'antlr4ts/TokenStreamRewriter';
import { BufferedTokenStream } from 'antlr4ts/BufferedTokenStream';
import { Token } from 'antlr4ts/Token';

export function tokenStreamToList(tokens: BufferedTokenStream): Token[]  {
	let tokenList: Token[] = [];
	tokens.seek(0);
	let token:Token = tokens.LT(1);
	while (token.type != Token.EOF) {
		tokens.consume();
		tokenList.push(token);
		token = tokens.LT(1);
	}
	tokens.seek(0);
	return tokenList;
}

export function isLibFunc(posAstStr: string): boolean {
	const libFuncs = 'ASCIIDelete|ASCIIOutput|CloseTextFile|WriteTextFile|CalcDim|CalcDimEx|CellGetN|CellGetS|CellIncrementN|CellPutN|CellPutS|CellIsUpdateable|CubeExists|DBCellGetN|DBCellGetS|DefSplitDims|Expr|ExprEx|GetCellType|XCellGetN|XCellGetS|BuildMemberSet|DimensionExists|DimensionElementPrincipalName|ExecuteCommand|ExecuteCommandEx|ExecuteScript|GetScriptName|IsOriginScript|RunScript|ScriptError|ScriptQuit|ViewClearData|ViewZeroOut|AvgRange|IsMbr|PRIOR|SumRange|COUNT|RANK|SUM|CombineMemberSet|GenMembers|GenNextMember|GenPrevMember|AddArrayItem|CombineArray|CombineArrayUnique|DuplicateArray|ExceptArray|GetArrayItemCount|IntersectArray|IsInArray|SetArrayItem|StrArrayToMemberSet|DetailOutput|FileExists|LogOutput|NumberToString|StringToNumber|WildcardFileSearch'.split('|').map(item => item.toLowerCase());
	return libFuncs.includes(posAstStr.toLowerCase());
}

